#!/usr/bin/env python
# -*- coding: utf-8 -*-
# title       :
# author      : jarry

import sys
import os
import logging
from SceneCheckTool.checkScript.CheckBase import CheckBase

try:
    import maya.cmds as cmds
    import pymel.core as pm
    import jarryLibs.mayakit.MayaUtils as mu
    reload(mu)
    import elsLibs.ShotInfoFromFile as elssif
    reload(elssif)
except:
    pass

logging.basicConfig()
log = logging.getLogger(__name__)
log.setLevel(logging.DEBUG)


class CheckELSAniFileName(CheckBase):
    def __init__(self):
        super(CheckELSAniFileName, self).__init__()
        self.ani_match = ['ani_lay', 'ani_blk', 'ani_1st', 'ani_fin']
        self.end_ext = '.ma'

    def check(self):
        current_file = mu.sceneName()

        if not current_file:
            result_log = u'Error: 当前文件未保存!'
            return result_log
        if current_file.startswith('els_'):
            result_log = u'Error: 当前文件非els项目镜头规则,缺少els_!'
            return result_log
        if not current_file.endswith(self.end_ext):
            result_log = u'Error: 结尾格式不对,要求是.ma'
            return result_log

        sif = elssif.ShotInfoFromFile(current_file)
        result_log = 'Succeed:'
        try:
            self.seqshot = sif.get_seqshot
            if self.seqshot:
                result_log += u'<br><font color=\"#007900\">场次镜头号:%s' % self.seqshot
            else:
                raise
        except:
            result_log += u'<br><font color=\"#FF0000\">缺少场景镜头号规则s001c001'
        try:
            self.step = sif.get_step
            if self.step in self.ani_match:
                result_log += u'<br><font color=\"#007900\">动画制作阶段:%s' % self.step
            else:
                raise
        except:
            result_log += u'<br><font color=\"#FF0000\">缺少制作阶段规则ani_lay,ani_blk,ani_1st,ani_fin'
        try:
            self.version = sif.get_version
            if self.version:
                result_log += u'<br><font color=\"#007900\">大版本:%s' % self.version
            else:
                raise
        except:
            result_log += u'<br><font color=\"#FF0000\">缺少版本号v###'
        try:
            self.art = sif.get_art
            result_log += u'<br><font color=\"#007900\">艺术家:%s' % self.art
        except:
            result_log += u'<br><font color=\"#FF0000\">缺少艺术家后缀'

        if u'缺少' in result_log:
            result_log = result_log.replace('Succeed:', 'Error:')

        return result_log

    def fix(self):
        pass